from django.contrib.auth.models import AbstractUser
from django.db import models

class User(AbstractUser):
    ROLE_CHOICES = (
        ('student', '学生'),
        ('teacher', '教师'),
        ('admin', '管理员'),
    )
    role = models.CharField(max_length=10, choices=ROLE_CHOICES)
    real_name = models.CharField(max_length=50, verbose_name='姓名')
    gender = models.CharField(max_length=10, choices=(('男', '男'), ('女', '女')), blank=True)
    phone = models.CharField(max_length=20, blank=True)
    id_card = models.CharField(max_length=20, blank=True)
    college = models.CharField(max_length=50, blank=True)
    grade = models.CharField(max_length=10, blank=True)
    clazz = models.CharField(max_length=10, blank=True)
    photo = models.ImageField(upload_to='photos/', null=True, blank=True)

    USERNAME_FIELD = 'username'
    REQUIRED_FIELDS = ['role', 'real_name']

    def __str__(self):
        return f"{self.username}({self.get_role_display()})" 